﻿using System;
using fastCSharp;

namespace diantou.dataModel.sqlMember
{
    /// <summary>
    /// 图片
    /// </summary>
    [fastCSharp.emit.dataSerialize(IsReferenceMember = false, IsMemberMap = false)]
    [fastCSharp.emit.dataMember(DataType = typeof(string))]
    [fastCSharp.code.cSharp.webView.clientType(Name = "diantou.image", MemberName = null)]
    public partial struct image
    {
        /// <summary>
        /// URL原始值
        /// </summary>
        [fastCSharp.code.cSharp.webView.outputAjax]
        public string Value;
        /// <summary>
        /// 是否全名称
        /// </summary>
        private unsafe bool isFullName
        {
            get
            {
                return fastCSharp.web.formatHtml.IsHttpOrDefalut(Value);
            }
        }
        /// <summary>
        /// 图片URL
        /// </summary>
        /// <param name="value">URL原始值</param>
        public image(string value)
        {
            Value = value;
        }
        public static implicit operator image(string value) { return new image { Value = value }; }
        public static implicit operator string(image image) { return image.Value; }
        /// <summary>
        /// 原始路径
        /// </summary>
        [fastCSharp.code.ignore]
        public string Src
        {
            get { return size(null); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P25
        {
            get { return size("ti_25_25/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P40
        {
            get { return size("ti_40_40/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P50
        {
            get { return size("ti_50_50/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P100
        {
            get { return size("ti_100_100/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string W100
        {
            get { return size("ti_100_/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string W100H150
        {
            get { return size("ti_100_150/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P150
        {
            get { return size("ti_150_150/"); }
        }
        /// <summary>
        /// 缩略图
        /// </summary>
        [fastCSharp.code.ignore]
        public string P200
        {
            get { return size("ti_200_200/"); }
        }
        /// <summary>
        /// 格式化图片URL
        /// </summary>
        /// <param name="dir">尺寸路径</param>
        /// <returns>图片URL</returns>
        private string size(string dir)
        {
            return Value.length() != 0 ? (isFullName ? Value : ("//" + diantou.dataModel.path.domain.Default.ImageDomain + "/" + dir + Value)) : null;
        }
    }
}
